package com.cp.admin.modular.system.controller;

import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.system.model.Share;
import com.cp.admin.modular.system.service.IShareService;

/**
 * 推广链接控制器
 *
 * @author fengshuonan
 * @Date 2020-05-13 18:06:33
 */
@Controller
@RequestMapping("/share")
public class ShareController extends BaseController {

    private String PREFIX = "/system/share/";

    @Autowired
    private IShareService shareService;

    /**
     * 跳转到推广链接首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "share.html";
    }

    /**
     * 跳转到添加推广链接
     */
    @RequestMapping("/share_add")
    public String shareAdd() {
        return PREFIX + "share_add.html";
    }

    /**
     * 跳转到修改推广链接
     */
    @RequestMapping("/share_update/{shareId}")
    public String shareUpdate(@PathVariable Long shareId, Model model) {
        Share share = shareService.selectById(shareId);
        model.addAttribute("item",share);
        LogObjectHolder.me().set(share);
        return PREFIX + "share_edit.html";
    }

    /**
     * 获取推广链接列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return shareService.selectList(null);
    }

    /**
     * 新增推广链接
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Share share) {
        shareService.insert(share);
        return SUCCESS_TIP;
    }

    /**
     * 删除推广链接
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long shareId) {
        shareService.deleteById(shareId);
        return SUCCESS_TIP;
    }

    /**
     * 修改推广链接
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Share share) {
        shareService.updateById(share);
        return SUCCESS_TIP;
    }

    /**
     * 推广链接详情
     */
    @RequestMapping(value = "/detail/{shareId}")
    @ResponseBody
    public Object detail(@PathVariable("shareId") Long shareId) {
        return shareService.selectById(shareId);
    }
}
